//
//  PopularViewCell.m
//  NewMyMusicAPP
//
//  Created by 08- 张志强 on 15/6/20.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "PopularViewCell.h"

@implementation PopularViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatMake];
    }
    
    return self;

  
}

-(void)creatMake
{
    
    self.posterPic=[[[UIImageView alloc]init]autorelease];
    self.posterPic.frame=CGRectMake(0, 0,WIDTH * 375,HEIGHT * 200);
    self.posterPic.contentMode = UIViewContentModeScaleToFill;
    [self.posterPic setClipsToBounds:YES];
    [self.posterPic setContentMode:UIViewContentModeScaleToFill];
    //self.posterPic.alpha=1.5;
    [self.contentView addSubview:self.posterPic];
    
    //加个view 调节背景亮度
    UIView *myView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH * 375, HEIGHT * 200)]autorelease];
    myView.backgroundColor = [UIColor blackColor];
    myView.alpha = 0.2;//透明度
    [self.posterPic addSubview:myView];
    
    
    self.titleLable = [[[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 15,HEIGHT * 150,WIDTH * 200,HEIGHT * 20)]autorelease];
    self.titleLable.backgroundColor=[UIColor clearColor];
    self.titleLable.font=[UIFont systemFontOfSize:15];
      [self.titleLable setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//字体加粗
    self.titleLable.textColor=[UIColor whiteColor];
    self.titleLable.textAlignment=NSTextAlignmentLeft;
    [self.posterPic addSubview:self.titleLable];
    
    
    self.artistNameLable= [[[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 15,HEIGHT * 170,WIDTH * 200,HEIGHT * 20)]autorelease];
    self.artistNameLable.backgroundColor=[UIColor clearColor];
    self.artistNameLable.font=[UIFont systemFontOfSize:15];
      [self.artistNameLable setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//字体加粗
    self.artistNameLable.textColor=[UIColor orangeColor];
    self.artistNameLable.textAlignment=NSTextAlignmentLeft;
    
    [self.posterPic addSubview:self.artistNameLable];
    
    
    //收藏按钮
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(WIDTH * 330, HEIGHT * 30, WIDTH * 27, WIDTH * 25);
    [self.button addTarget:self action:@selector(collect) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
}

-(void)collect
{
    CollectModel *collect = [[[CollectModel alloc] init]autorelease];
    collect.title = self.popularModel.title;
    collect.modelId = self.popularModel.idd;
    collect.type=@"VIDEO";
    
    
    if (self.buer == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] insertCollect:collect];
        self.buer = YES;
        NSLog(@"添加收藏 NO  ==  id = %@",collect.modelId);
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] deleteTable:collect.modelId];
        self.buer = NO;
        NSLog(@"删除收藏 YES ==  id = %@",collect.modelId);
    }
    
}



-(void)setPopularModel:(PopularModel *)popularModel

{
    if (_popularModel != popularModel) {
        [_popularModel release];
        _popularModel = [popularModel retain];
    }
    
    
    
    
    self.titleLable.text=self.popularModel.title;
    self.artistNameLable.text = self.popularModel.artistName;
    
    if (self.popularModel.albumImg.length==0) {
        
        
        NSURL *url = [NSURL URLWithString:self.popularModel.posterPic];
        [self.posterPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
    }else
    {
        NSURL *url = [NSURL URLWithString:self.popularModel.albumImg];
        [self.posterPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
    }

    if (self.buer == YES) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        
        
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
        
    }

}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
